﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace sy2_3
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void button2_Click(object sender, EventArgs e)
        {
            // 清空输入和结果文本框
            txtInput.Text = "";
            txtResult.Text = "";
        }

        private void label1_Click(object sender, EventArgs e)
        {

        }

        private void btnCalculate_Click(object sender, EventArgs e)
        {
            
            // 获取输入的字符串
            string inputStr = txtInput.Text;
            double n;
            // 尝试将输入的字符串转换为 double 类型
            if (double.TryParse(inputStr, out n))
            {
                int result;
                // 根据 n 的值确定符号函数的结果
                if (n < 0)
                {
                    result = -1;
                }
                else if (n == 0)
                {
                    result = 0;
                }
                else
                {
                    result = 1;
                }
                // 将结果显示在结果文本框中
                txtResult.Text = result.ToString();
            }
            else
            {
                // 如果输入无法转换为数字，给出提示
                MessageBox.Show("请输入有效的数字！");
            }
        }
    }
    }

